<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="tuSecure.Alert" %>
<%@ page import="tuSecure.PMF" %>

<html>
  <body>

<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with greetings you post.</p>
<%
    }
%>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Alert.class.getName();
    List<Alert> alrts = (List<Alert>) pm.newQuery(query).execute();
    if (alrts.isEmpty()) {
%>
<p>There are no messages.</p>
<%
    } else {
        for (Alert a : alrts) {
 %>
		<p>Symbol:</p>           
		<%= a.getSymbol() %>
		<p>Content:</p>           
		<%= a.getContent() %>
		<p>Type:</p>           
		<%= a.getType() %>
		<p>Phone:</p>           
		<%= a.getPhone() %>
		<p>Comment:</p>           
		<%= a.getComment() %>
 		<p>Latitude:</p>           
		<%= a.getLatitude() %>
		<p>Longitude:</p> 
		<%= a.getLongitude() %>
		<p>Date:</p>           
		<%= a.getDate() %>
		
<%
        }
    }
    pm.close();
%>

    <form action="/sign" method="post">
      <div><textarea name="content" rows="3" cols="60"></textarea></div>
      <div><input type="submit" value="Post Greeting" /></div>
    </form>

	
	<p><a href="map.jsp">SEE MAP!</a></p>
	<p><a href="maptime.jsp">SEE MAPtime!</a></p>
  </body>
</html>